﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MyAnim.Models;

namespace MyAnim.Controllers
{
    public class TeamController : Controller
    {
        //
        // GET: /Team/

        public ActionResult Index()
        {

            if (Session["User"] != null)
            {
            }
            return View();
        }




        //
        // GET: /Team/Details/5

        public ActionResult Details(int id)
        {
            return View();
        }

        //
        // GET: /Team/Create

        public ActionResult Create()
        {
            return View();
        }

        public ActionResult Register()
        {
            if (Session["User"] != null)
            {
                return View("Index");
            }
            return View();
        }

        [HttpPost]
        public ActionResult Register(TeamRegisterModel model)
        {
            if (ModelState.IsValid)
            {
                
                try
                {
                    var mail = new System.Net.Mail.MailMessage("admin@animu.net", "jmgueirard@gmail.com");

                    mail.Subject = "New team " + model.UserName;
                    mail.Body = "SiteWeb:" + model.Siteweb + Environment.NewLine;
                    mail.Body += "UserName:" + model.UserName + Environment.NewLine;
                    mail.Body += "Mail:" + model.Email + Environment.NewLine;
                    mail.Body += "Comment:" + model.Comment + Environment.NewLine;
                    mail.Body += "NbSerie:" + model.NbAnime + Environment.NewLine;
                    mail.Body += "SubmitDate:" + DateTime.Now;

                    mail.IsBodyHtml = false;
            

                    var smtp = new System.Net.Mail.SmtpClient();
                    smtp.Send(mail);
                }
                catch (Exception)
                {
                    return View();
                    throw;
                }
                
            }

            // Si nous sommes arrivés là, quelque chose a échoué, réafficher le formulaire
            return View(model);
        }

        //
        // POST: /Team/Create

        [HttpPost]
        public ActionResult Create(FormCollection collection)
        {
            try
            {
                // TODO: Add insert logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
        
        //
        // GET: /Team/Edit/5
 
        public ActionResult Edit(int id)
        {
            return View();
        }

        //
        // POST: /Team/Edit/5

        [HttpPost]
        public ActionResult Edit(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add update logic here
 
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        //
        // GET: /Team/Delete/5
 
        public ActionResult Delete(int id)
        {
            return View();
        }

        //
        // POST: /Team/Delete/5

        [HttpPost]
        public ActionResult Delete(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add delete logic here
 
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        public ActionResult TeamFiles()
        {
            return View();
        }
    }
}
